//图片转base64
// 定义网络图转base64的方法
export function getBase64(img) {
    function getBase64Image(img) {
        var canvas = document.createElement("canvas");
        canvas.width = img.width;
        canvas.height = img.height;
        var ctx = canvas.getContext("2d");
        ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
        var dataURL = canvas.toDataURL();
        // console.log('dataURL',dataURL)
        return dataURL;
    }

    var image = new Image();
    image.setAttribute('crossOrigin', 'anonymous')//解决跨域
    image.crossOrigin = '*';
    image.src = img;
    console.log('img',img)
    return new Promise((resolve, reject) => {
        image.onload = function () {
            resolve(getBase64Image(image));//将base64传给done上传处理
        }
    });
}

//
// var imgUrl = 'http://192.168.2.211:8000/media/card_photo/141234567.png';
// getBase64(imgUrl, 'png', function(base64){
//     // 给原生img对象的src属性赋值
//     let img = base64;
//     console.log('img.src',img)
// })
